package com.jiangnan.mapper;

import com.jiangnan.pojo.Emp;
import com.jiangnan.pojo.EmpQueryParam;
import com.jiangnan.pojo.LoginInfo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    // ------------------------------ 原始的分页查询 ---------------------------------
//    /**
//     * 查询总记录数
//     * @return
//     */
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id;")
//    Long count();
//
//    /**
//     * 分页查询
//     */
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "order by e.update_time desc limit #{start}, #{pageSize}")
//    List<Emp> list(Integer start,Integer pageSize);

    // ------------------------------ PageHelper的分页查询 ---------------------------------
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "order by e.update_time desc")
    List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")  // 插入数据后，返回主键值
    @Insert("insert into emp (username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time,update_time)" +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteBatch(List<Integer> ids);


    Emp getById(Integer id);

    void updateById(Emp emp);

    List<Map<String, Object>> countEmpJobData();

    List<Map<String, Object>> countEmpGenderData();

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}
